package com.example.shop.service.impl;

import com.example.shop.mapper.CommodityTypeMapper;
import com.example.shop.model.CommodityType;
import com.example.shop.service.CommodityTypeService;
import com.example.shop.utils.PageBean;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommodityTypeServiceImpl implements CommodityTypeService {
    @Resource
    private CommodityTypeMapper commodityTypeMapper;

    public PageBean<CommodityType> getCommodityType(int pageNo, int pageSize, String search) {
        PageBean<CommodityType> pageBean = new PageBean<>();
        pageBean.setPageSize(pageSize);
        pageBean.setDataCount(commodityTypeMapper.getDataCount());
        pageBean.setPageNo(pageNo);
        if ("".equals(search) || search.length() == 0) {
            search = null;
        }
        List<CommodityType> users = commodityTypeMapper.getCommodityType((pageNo - 1) * pageSize, pageSize, search);
        pageBean.setDataList(users);
        return pageBean;
    }
}
